using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;

namespace MLTimeline.Editor
{
    public class TrackPlateView : VisualElement
    {
        private static readonly List<VisualElement> _emptyList = new List<VisualElement>();

        public IEnumerable ClipViews
        {
            get
            {
                if (contentContainer == this)
                {
                    return hierarchy.Children();
                }
                return contentContainer?.Children() ?? _emptyList;
            }
        }

        public TrackPlateView()
        {
            CreateGUI();
        }
        private void CreateGUI()
        {
            var loader = TimelineEditorLoader.Instance;
            if (loader == null)
            {
                Debug.LogWarning("当前加载器不存在。");
                return;
            }
            if (loader.trackPlateView == null)
            {
                Debug.LogWarning("track-plate-view.uxml文件不存在，请检查下，是否将uxml文件拖入TimelineEditorLoader.cs文件的Inspector面板内。");
                return;
            }
            loader.trackPlateView.CloneTree(this);
        }

        public void AddClip(int startFrame, int endFrame, float startPixel, float endPixel)
        {
            var clipView = new ClipView();
            clipView.StartFrame = startFrame;
            clipView.EndFrame = endFrame;
            var width = endPixel - startPixel;
            clipView.style.left = startPixel;
            clipView.style.width = width;
            Add(clipView);
        }
    }
}